import datetime
from applications.extensions import db
from .spider_category import CategoryModel


class LatestTimeModel(db.Model):
    __tablename__ = 'spider_latest'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment="最新时间记录器的ID")
    name = db.Column(db.String(255), comment='名称')
    time = db.Column(db.Integer, comment="上一次的更新时间")
    details = db.Column(db.String(255), comment='详情')
    create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_at = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='创建时间')
    category_id = db.Column(db.Integer, db.ForeignKey("spider_category.id"))
    category = db.relationship("CategoryModel", backref=db.backref("latest_time", order_by=create_at.desc()))
